<template>
  <div>
    <div class="login-left">
      <p>魅优蜂后台管理系统</p>
      <h3>cslt auto repair management system</h3>
      <img src="../../assets/login_left.png" alt="" />
    </div>
    <div class="login-right">
      <div class="logo">
        <img src="../../assets/login_yp.png" alt="" />
      </div>
      <h1>魅优蜂管理系统</h1>
      <el-form
        ref="loginForm"
        :model="form"
        :rules="rules"
        size="large"
        @keyup.enter.native="doSubmit"
      >
        <el-form-item prop="account">
          <el-input
            placeholder="请输入登录账号"
            v-model="form.account"
            prefix-icon="el-icon-user"
            clearable
            class="ipt"
          />
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            placeholder="请输入登录密码"
            v-model="form.password"
            prefix-icon="el-icon-lock"
            show-password
          />
        </el-form-item>
        
        <div class="remanber">
          <el-checkbox v-model="form.remember">记住我的账户</el-checkbox>
        </div>
        <div class="btn">
          <el-button
            @click="submit"
            :loading="loading"
            type="primary"
            class="login-btn"
            size="large"
          >
            {{ loading ? '登录中' : '登录' }}
          </el-button>
        </div>
      </el-form>
    </div>
  </div>
</template>
<script>
  import { getToken } from '@/utils/token-util';
  import { login } from '@/api/login';

  export default {
    // eslint-disable-next-line vue/multi-word-component-names
    name: 'Login',
    data() {
      return {
        // 登录框方向, 0居中, 1居右, 2居左
        direction: 0,
        // 加载状态
        loading: false,
        // 表单数据
        form: {
          // account: 'admin',
          // password: '111111',
          account: '',
          password: '',
          remember: true,
          code: '',
          dataSource: '1'
        },
        // 验证码base64数据
        captcha: '',
        // 验证码内容, 实际项目去掉
        text: ''
      };
    },
    computed: {
      // 表单验证规则
      rules() {
        return {
          account: [
            {
              required: true,
              message: '请输入账号',
              trigger: 'blur',
              type: 'string'
            }
          ],
          password: [
            {
              required: true,
              message: '请输入密码',
              trigger: 'blur',
              type: 'string'
            }
          ]
        };
      },
      // 当前语言
      language() {
        return this.$i18n.locale;
      }
    },
    created() {
      if (getToken()) {
        this.goHome();
      }
    },
    methods: {
      /* 提交 */
      submit() {
        this.$refs['loginForm'].validate((valid) => {
          //验证必填
          if (!valid) {
            return false;
          }

          this.loading = true;
          login(this.form)
            .then((msg) => {
              this.loading = false;
              this.$message.success(msg);
              this.goHome();
            })
            .catch((e) => {
              this.loading = false;
              this.$message.error(e.message);
            });
        });
      },
      /* 跳转到首页 */
      goHome() {
        this.$router.push(this.$route?.query?.from ?? '/').catch(() => {});
      },
      /* 切换语言 */
      changeLanguage(lang) {
        this.$i18n.locale = lang;
        localStorage.setItem('i18n-lang', lang);
      }
    }
  };
</script>
<style lang="scss" scoped>
  .logo {
    width: 100px;
    height: 32px;
    position: absolute;
    right: 39%;
    top: -28%;
  }
  h1 {
    position: absolute;
    font-size: 28px;
    right: 28%;
    top: -15%;
    font-weight: 700;
  }
  .login-left {
    width: 50%;
    height: 100vh;
    position: relative;
    left: 0;
    top: 0;
    p {
      position: absolute;
      left: 80px;
      top: 46%;
      font-size: 40px;
      color: #fff;
      border-bottom: 1px solid #fff;
      padding-bottom: 27px;
    }
    h3 {
      position: absolute;
      left: 80px;
      top: 57%;
      font-size: 18px;
      color: #fff;
    }
  }
  .cod {
    width: 150px;
    height: 70px;
    float: left;
    margin-top: 30px;
    margin-left: 30px;
  }
  img {
    width: 100%;
    height: 100%;
  }
  p .login-wrapper:before {
    content: '';
    background-color: rgba(0, 0, 0, 0.2);
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
  }

  .login-form {
    margin: 0 auto;
    width: 360px;
    max-width: 100%;
    padding: 25px 30px;
    position: relative;
    box-shadow: 0 3px 6px rgba(0, 0, 0, 0.15);
    box-sizing: border-box;
    border-radius: 4px;
    z-index: 2;
  }

  .login-form-right .login-form {
    margin: 0 15% 0 auto;
  }

  .login-form-left .login-form {
    margin: 0 auto 0 15%;
  }

  .login-form h4 {
    text-align: center;
    margin: 0 0 25px 0;
  }

  .login-form > .el-form-item {
    margin-bottom: 25px;
  }

  .login-input-group {
    display: flex;
    align-items: center;
  }

  .login-input-group >>> .el-input {
    flex: 1;
  }

  .login-captcha {
    height: 38px;
    width: 102px;
    margin-left: 10px;
    border-radius: 4px;
    border: 1px solid #dcdfe6;
    text-align: center;
    cursor: pointer;
  }

  .login-captcha:hover {
    opacity: 0.75;
  }

  .login-btn {
    margin-top: 30px;
    display: block;
    width: 100%;
    background-color: blue;
    border-radius: none;
    height: 70px;
    border-radius: 15px;
  }
  .btn {
    display: inline-block;
    width: 90%;
  }
  .login-oauth-icon {
    color: #fff;
    padding: 5px;
    margin: 0 10px;
    font-size: 18px;
    border-radius: 50%;
    cursor: pointer;
  }

  .login-copyright {
    color: #eee;
    padding-top: 20px;
    text-align: center;
    position: relative;
    z-index: 1;
  }

  @media screen and (min-height: 550px) {
    .login-form {
      position: absolute;
      top: 50%;
      left: 50%;
      transform: translateX(-50%);
      margin-top: -220px;
    }

    .login-form-right .login-form,
    .login-form-left .login-form {
      left: auto;
      right: 15%;
      transform: translateX(0);
      margin: -220px auto auto auto;
    }

    .login-form-left .login-form {
      right: auto;
      left: 15%;
    }

    .login-copyright {
      position: absolute;
      bottom: 20px;
      right: 0;
      left: 0;
    }
  }

  @media screen and (max-width: 768px) {
    .login-form-right .login-form,
    .login-form-left .login-form {
      left: 50%;
      right: auto;
      transform: translateX(-50%);
      margin-right: auto;
    }
  }
  .login-right {
    width: 500px;
    height: 500px;
    position: absolute;
    right: 11%;
    top: 26%;
    background-color: #fff;
    padding: 15px;
    border-radius: 15px;
    text-align: center;
  }
  ::v-deep .el-input {
    margin-top: 30px;
    border: none;
    width: 90%;
  }
  ::v-deep .el-input__inner {
    border: none;
    background-color: #f8f8f8;
    height: 70px !important;
  }
  .remanber {
    float: left;
    margin-left: 20px;
  }
  ::v-deep .el-input__icon {
    color: #909399;
    font-weight: 600;
    font-size: 18px;
    // margin-right: 10px;
    // margin-left: 10px;
  }
  ::v-deep .login-btn[data-v-a49090ce] {
    font-size: 18px;
  }
  ::v-deep [data-v-a49090ce] .el-input__inner {
    font-size: 18px;
  }
</style>
